<template>
  <div>
    <div class="main">
      <el-container>
        <!-- 主体部分 -->
        <el-main style="line-height:35px">
          <!-- 展示部分 -->
          <el-card class="box-card" style="margin-top:20px;margin-left:-30px;width:1155px">
            <div>
              <div style="line-height:20px">
                <strong style="float:left">统一几折</strong>
              </div>
              <div class="clear"></div>
              <el-divider></el-divider>
              <strong class="font">系统一律销售折扣为</strong>
              <el-input
                v-model="input"
                placeholder="请输入内容"
                style="display:inline-block;width:200px;margin-left:-300px"
              ></el-input>
              <span style="color:blue;margin-left:30px">填写0-1之间的小数，如0.5</span>
              <el-button type="primary" style="margin-left:40px" @click="add">保存</el-button>
            </div>
          </el-card>
        </el-main>
      </el-container>
    </div>
  </div>
</template>

<script>
import Qs from "qs";
import store from "../../store";

export default {
  data() {
    return {
      input: ""
    };
  },
  created() {
    this.rendering();
  },
  methods: {
    rendering() {
      // this.$axios({
      //   url: "/getAllDiscount",
      //   method: "get"
      // }).then(res => {
      //   // console.log(res);
      //   this.input = res.data.alldiscount;
      // });
      this.$store.dispatch("discount").then(res => {
        // console.log(store.state.alldiscount);
        this.input = store.state.alldiscount;
      });
    },
    add() {
      this.$axios({
        url: "/updateAllDiscount",
        method: "post",
        data: Qs.stringify({ allrule: this.input }),
        headers: { "content-type": "application/x-www-form-urlencoded" }
      }).then(res => {
        console.log(res);
        this.$message({
          type: "info",
          message: res.data.msg
        });
        this.rendering();
      });
    }
  }
};
</script>

<style>
.font {
  font-size: 20px;
  margin-left: 70px;
  float: left;
  height: 180px;
}
</style>